//
//  ZYOnlineComponent.m
//  DesignMode
//
//  Created by wangzhipan on 2024/11/7.
//

#import "ZYOnlineComponent.h"

@implementation ZYOnlineComponent

- (instancetype)initWithComponentId:(NSString *)componentId priority:(NSUInteger)priority
{
    if (self = [super initWithComponentId:componentId priority:priority]) {
        [self initUI];
    }
    return self;
}

- (void)initUI
{
    int r = arc4random() % 5;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(r * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self loadComponentViewIfNeed:nil];
    });
}

- (void)layoutInSuperComponentView:(UIView *)superView
{
    int y = arc4random() % 400;
    int x = arc4random() % 200;
    self.componentView.frame = CGRectMake(x, y, 100, 100);
    
}

- (BOOL)isLazyLoadUI
{
    return true;
}

- (nullable UIView *)lazyLoadView
{
    UIView *componentView = [[UIView alloc] init];
    int r = arc4random() % 5;
    if (r == 0) {
        componentView.backgroundColor = [UIColor redColor];
    }
    
    if (r == 1) {
        componentView.backgroundColor = [UIColor yellowColor];
    }
    
    if (r == 2) {
        componentView.backgroundColor = [UIColor blackColor];
    }
    
    if (r == 3) {
        componentView.backgroundColor = [UIColor greenColor];
    }
    
    if (r == 4) {
        componentView.backgroundColor = [UIColor orangeColor];
    }
    
    return componentView;
}
@end
